package com.cxyzy.demo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.ToastUtils

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        parseJsonByFastJson()
    }

    private fun parseJson() {
        val jsonStr = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}"
        val map = JsonUtil.jsonToMap(jsonStr)
        ToastUtils.showShort("语文成绩：" + map?.get("语文").toString())
    }

    private fun parseJsonByFastJson() {
        val jsonStr = "{\"语文\":\"88\",\"数学\":\"78\",\"计算机\":\"99\"}"
        val map = JSON.parse(jsonStr)
        if (map is Map<*, *>) {
            ToastUtils.showShort("语文成绩：" + map["语文"]?.toString())
        }
    }

}
